import axios from 'axios'

export default class Store {
  getNews(type, count, method = 'get') {
    const url = `http://newsapi.gugujiankong.com/Handler.ashx?action=getnews&type=${type}&count=${count}`
    return axios(url, method).then(res => res.data)
  }

  getNewDetail(uniquekey, method = 'get') {
    const url = `http://newsapi.gugujiankong.com/Handler.ashx?action=getnewsitem&uniquekey=${uniquekey}`
    return axios(url, method).then(res => res.data)
  }

  getComments(uniquekey, method = 'get') {
    const url = `http://newsapi.gugujiankong.com/Handler.ashx?action=getcomments&uniquekey=${uniquekey}`
    return axios(url, method).then(res => res.data)
  }

  getUserCollection(userId, method = 'get') {
    const url = `http://newsapi.gugujiankong.com/Handler.ashx?action=getuc&userid=${userId}`
    return axios(url, method).then(res => res.data)
  }
  
  getUserComments(userId, method = 'get') {
    const url = `http://newsapi.gugujiankong.com/Handler.ashx?action=getusercomments&userid=${userId}`
    return axios(url, method).then(res => res.data)
  }

}

export const store = new Store()